package com.mozz.finally_work.servlet;

import com.mozz.finally_work.dao.CollectionDao;
import com.mozz.finally_work.utils.MybatisUtils;
import org.apache.ibatis.session.SqlSession;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;


/*取消收藏*/
@WebServlet(name = "UnCollectionServlet", value = "/UnCollectionServlet")
public class UnCollectionServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String blogId = request.getParameter("blogId");
        String userId = request.getParameter("userId");
        /*调用dao取消收藏*/
        SqlSession session = MybatisUtils.getSession();
        CollectionDao dao = session.getMapper(CollectionDao.class);
        Integer integer = dao.unCollectionBlog(userId, blogId);
        session.commit();
        session.close();
        response.sendRedirect("UserCollectionsServlet?userId="+userId);
    }
}
